package cn.tedu.login.service.impl;

import cn.tedu.base.exception.ServiceException;
import cn.tedu.base.response.StatusCode;
import cn.tedu.login.mapper.LoginMapper;
import cn.tedu.login.pojo.dto.LoginParam;
import cn.tedu.login.pojo.entity.Login;
import cn.tedu.login.pojo.vo.LoginVO;
import cn.tedu.login.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;
    @Override
    public LoginVO login(LoginParam loginParam) {
        log.debug("这是登录数据第二次传递：" + loginParam);
        LoginVO loginVO = loginMapper.selectByUsername(loginParam.getUsername());
        if (loginVO == null) {
            throw new ServiceException(StatusCode.USERNAME_ERROR);
        }
        if (!loginVO.getPassword().equals(loginParam.getPassword())) {
            throw new ServiceException(StatusCode.PASSWORD_ERROR);
        }
        return loginVO;
    }
}
